#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e3 + 10, maxv = 2e4 + 10, mod = 998244353;
int cnt[maxv], A[maxn], d[maxn][maxv], dd[maxn][maxv];
int N;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        int b = A[i];
        d[b][0] = 1;
        for (int j = i - 1; j >= 0; --j) {
            int a = A[j];
            int c = b - a;
            if (!c) ++d[b][c];
            else if (c > 0) {
                if (!d[a][c]) d[b][c] = 2;
                else d[b][c] = d[a][c] + 1, d[a][c] = 0;
            } else {
                c = -c;
                if (!dd[a][c]) dd[b][c] = 2;
                else dd[b][c] = dd[a][c] + 1, dd[a][c] = 0;
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        int a = A[i];
        ++cnt[0];
        for (int c = 1; c < maxv; ++c) {
            if (d[a][c])
                cnt[c] += d[a][c];
            if (dd[a][c])
                cnt[c] += dd[a][c];
        }
    }
    long long ans = 0;
    for (int i = 0; i < maxv; ++i) {
        int t = cnt[i];
        t %= 31;
        ans = (ans + (1 << t)) % mod;
    }
    cout << ans;
    return 0;
}